package net.oschina.aibinxiao.job;

import lombok.Setter;
import org.quartz.*;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @Author: AiBinXiao
 * @Description: 获取jobDataMap的方式二：Job实现类中添加Setter方法对应jobDataMap的键值
 *               Quartz框架默认的JobFactory实现类在初始化Job实例时会自动调用这些Setter方法
 * @Date: 2017/10/12 8:35
 */

@Setter
public class HelloJob2 implements Job{

    private String jobMessage;
    private Float mathJobValue;
    private String triggerMessage;
    private Double doubleTriggerValue;

    public void execute(JobExecutionContext context) throws JobExecutionException {
        // 打印当前时间，格式为 yyyy-MM-dd HH:mm:ss
        Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        String dateStr = sdf.format(date);
        System.out.println("当前时间是：" + dateStr);
        // 编写具体业务逻辑类
        JobKey jobKey = context.getJobDetail().getKey();
        System.out.println("myjob2 name is: " + jobKey.getName() + " and group is: " + jobKey.getGroup());
        TriggerKey triggerKey = context.getTrigger().getKey();
        System.out.println("mytrigger2 name is: " + triggerKey.getName() + " and group is " + triggerKey.getGroup());

        // JobDataMap dataMap = context.getMergedJobDataMap();
        System.out.println("jobMessage is :" + jobMessage);
        System.out.println("mathJobValue id :" + mathJobValue);
        System.out.println("triggerMessage is:" + triggerMessage);
        System.out.println("doubleTriggerValue is:" + doubleTriggerValue);
    }
}
